package com.cxz.food.exception;

import com.cxz.food.domain.Response;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = CustomException.class)
    @ResponseBody
    public Response defaultErrorHandler(HttpServletRequest req, CustomException e) throws Exception {

        return new Response(e.getCode(),e.getMessage());
    }

}
